<template>
  <div class="list" ref="wrapper">
    <div>
      <div class="area">
        <div class="title border-topbottom">您的位置:</div>
        <div class="list-box">
          <div class="button-list local">{{this.$store.state.city}}</div>
        </div>
      </div>
      <div class="area">
        <div class="title border-topbottom">热门城市</div>
        <div class="list-box">
          <div class="button-list" v-for="item of hotCity" :key="item.id" @click="cityChange(item.name)">{{item.name}}</div>
        </div>
      </div>
      <div class="area" v-for="(Alph,key) of cities" :key="key" :ref="key">
        <div class="title border-topbottom">{{key}}</div>
        <div class="sort-box">
          <div class="sort-list border-bottom" v-for="item of Alph" :key="item.id" @click="cityChange(item.name)">{{item.name}}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'CityList',
  props: {
    hotCity: Array,
    cities: Object,
    letter: String
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.wrapper)
  },
  watch: {
    letter: function () {
      const el = this.$refs[this.letter][0]
      this.scroll.scrollToElement(el)
    }
  },
  methods: {
    cityChange: function (city) {
      this.$store.dispatch('cChange', city)
      this.$router.push('/')
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
  .list
    overflow: hidden
    position: absolute
    left: 0
    right: 0
    top: 1.58rem
    bottom: 0
    .border-topbottom
      &:after
        border-color:#ccc
      &:before
        border-color:#ccc
     .border-bottom
      &:before
        border-color:#ccc
    .title
      line-height: .6rem
      background: #eee
      font-size: .2rem
      color: #666
      padding-left: .2rem
    .list-box
      overflow: hidden
      padding: .2rem   0rem  0rem  0rem
      .button-list
        float: left
        line-height: .5rem
        font-size: .18rem
        text-align: center
        padding: 0rem  .8rem
        border: .02rem #ccc solid
        border-radius: .06rem
        margin-left:.2rem
        margin-bottom: .2rem
      .local
        color: $bgColor
        border: .02rem $bgColor solid
    .sort-box
      width: 100%

      .sort-list
        padding-left: .2rem
        height:.86rem
        line-height:.86rem
        font-size: .18rem

</style>
